package leetcode.algorithm.dynamicPlan;

import org.testng.annotations.Test;

import java.util.*;
import java.util.stream.Collectors;

public class Stream {

    static class Model{
        private int id;
        private String Name;
        private String Name1;

        public Model(int id, String name) {
            this.id = id;
            Name = name;
        }

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getName() {
            return Name;
        }

        public void setName(String name) {
            Name = name;
        }

        @Override
        public String toString() {
            return "Model{" +
                    "id=" + id +
                    ", Name='" + Name + '\'' +
                    '}';
        }
    }

    public static void main(String[] args) {
        Model model = new Model(1, "A");
//        String::toCharArray
//        Arrays.sort();
        Map<String, Integer> map = new HashMap<>();


        List<Model> list = new ArrayList<>();
        list.add(model);
//        Map<Integer, List<Model>> map = list.stream().collect(Collectors.groupingBy(m->m.getId()));
//        System.out.println(map);

//        Boolean[] flag = new Boolean[2];
//        System.out.println(flag[0]);
//        for(int i=0;i<2;i++)flag[i]=false;
//        System.out.println(flag[0]);
    }
    @Test
    public void ok(){
        int[] res = new int[2];
        res[0]=1;
        res[1]=2;
        Test(res);
        System.out.println(res[0]);
        List<int[]> list = new ArrayList<>();
        Boolean[] brr = new Boolean[2];
        System.out.println(brr[0]);
        Test(brr);
        System.out.println(brr[0]);
    }

    public void Test(Boolean[] brr){
        brr[0]=true;
    }
    public void Test(int[] res){
        res[0]=3;
    }


    List<int[]> list = new ArrayList<>();
    @Test
    public void merge() {
        int[][] intervals = {{1,3},{2,6},{8,10},{15,18}};
        int len = intervals.length;
        Boolean[] flag = new Boolean[len];
        for(int i=0;i<len;i++)flag[i]=false;
        int[] start = intervals[0];
        for(int i=1;i<len;i++){
            for(int j=i+1;j<len;j++){
                if(flag[j]==false)interval(intervals[i], intervals[j], flag, j);
                else continue;
            }
        }
        int[][] res = new int[list.size()][2];
        for(int i=0;i<list.size();i++){
            res[i]=list.get(i);
        }
        System.out.println(list.get(0)[0]+"  " +list.get(0)[1]);


    }

    //这里的是指向对象;所以cur指向的实际上就是start的地址
    public void interval(int[] cur, int[] nex, Boolean[] flag, int j ){
         String Name1;
        if((cur[0]>=nex[0]&&cur[0]<=nex[1])||(cur[1]>=nex[0]&&cur[1]<=nex[1])){
            cur[0]=Math.min(cur[0],nex[0]);

            cur[1]=Math.max(cur[1],nex[1]);
            System.out.println(cur);
            flag[j]=true;
        }

        if(j==flag.length-1) list.add(cur);
    }



}
